// components/cell_checkbox/checkbox.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    options: {
      type: "array",
      value: []
    },
    cid: {
      type: "string",
      value: ""
    },
    value: {
      type: "array",
      value: []
    },
    // ok: { //是否有确定按钮,如果有,则点击确定时触发ok事件,统一发送选中项
    //   type: "bool",
    //   value: false
    // }
  },

  /**
   * 组件的初始数据
   */
  data: {
    selected: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      this.setData({
        selected: event.detail,
      })
      this.triggerEvent('change', event.detail)
    },
    // onOk: function (event) {
    //   this.triggerEvent('ok', this.data.selected)
    // },
    toggle: function (event) {
      const {
        index
      } = event.currentTarget.dataset
      const selector = `.zr-checkbox-${this.data.cid}-${index}`
      const checkbox = this.selectComponent(selector)
      checkbox.toggle()
    },
    noop: function () {}
  }
})